home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Symantec Versions / C04 Speech / P05 Speech Channel / SpeechChannelIntro.c next >
Encoding:
C/C++ Source or Header  |  1995-08-31  |  2.3 KB  |  109 lines  |  [TEXT/KAHL]

  1. //____________________________________________________________
  2. //    SpeechChannelIntro.c
  3. //
  4. //    Copyright © Dan Parks Sydow, 1995
  5. //    From the book:
  6. //    "Graphics and Sound Programming Techniques for the Mac",
  7. //    M&T Books, 1995
  8.  
  9.  
  10. //____________________________________________________________
  11.  
  12. #include <Speech.h>
  13.  
  14.  
  15. //____________________________________________________________
  16.  
  17. void           InitializeToolbox( void );
  18. Boolean        IsSpeechAvailable( void );
  19. SpeechChannel  OpenOneSpeechChannel( void );
  20.  
  21.  
  22. //____________________________________________________________
  23.  
  24. void  main( void )
  25.    OSErr          theError;
  26.    Boolean        speechPresent;
  27.    SpeechChannel  theChannel;
  28.    Str255         theString =  "\pUsing my own speech channel";
  29.    
  30.    InitializeToolbox();
  31.  
  32.    speechPresent = IsSpeechAvailable();
  33.    if ( speechPresent == false )
  34.       ExitToShell();
  35.  
  36.    theChannel = OpenOneSpeechChannel();
  37.    if ( theChannel == nil )
  38.       ExitToShell();
  39.  
  40.    theError = SpeakText( theChannel, (Ptr)(theString + 1), theString[0] );
  41.    if ( theError != noErr )
  42.       ExitToShell();
  43.  
  44.    while ( SpeechBusy() == true )
  45.       ;
  46.             
  47.    theError = DisposeSpeechChannel( theChannel );
  48.    if ( theError != noErr )
  49.       ExitToShell();
  50. }
  51.  
  52.  
  53. //____________________________________________________________
  54.  
  55. SpeechChannel  OpenOneSpeechChannel( void )
  56. {
  57.    SpeechChannel  theChannel;   
  58.    OSErr          theError;
  59.    
  60.    theError = NewSpeechChannel( nil, &theChannel );
  61.    
  62.    if ( theError != noErr )
  63.    {
  64.       theError = DisposeSpeechChannel( theChannel );
  65.       theChannel = nil;
  66.    }
  67.       
  68.    return ( theChannel );
  69. }
  70.  
  71.  
  72. //____________________________________________________________
  73.  
  74. Boolean  IsSpeechAvailable( void )
  75. {
  76.    OSErr    theError;
  77.    long     theResult;
  78.    Boolean  speechAvail;
  79.    
  80.    theError = Gestalt( gestaltSpeechAttr, &theResult );
  81.    if ( theError != noErr )
  82.       ExitToShell();
  83.       
  84.    speechAvail = theResult & ( 1 << gestaltSpeechMgrPresent );  
  85.    if ( speechAvail > 0 )
  86.       return ( true );
  87.    else
  88.       return ( false );
  89. }
  90.  
  91.  
  92. //____________________________________________________________
  93.  
  94. void  InitializeToolbox( void )
  95. {
  96.    InitGraf( &qd.thePort );
  97.    InitFonts();
  98.    InitWindows();
  99.    InitMenus();
  100.    TEInit();
  101.    InitDialogs( 0L );
  102.    FlushEvents( everyEvent, 0 );
  103.    InitCursor();
  104. }
  105.  
  106.  
  107.  
  108.